from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from zope.app.schema.vocabulary import IVocabularyFactory
from zope.interface import implements
from my315ok.fangcan import fangcanMessageFactory as _

from zope.interface import directlyProvides
#from zope.schema.interfaces import IVocabularyFactory
#from zope.schema.vocabulary import SimpleVocabulary
from my315ok.fangcan.interfaces import Ihouse
from Products.CMFCore.utils import getToolByName
def SubdistrictVocabularyFactory(context):
    """Vocabulary factory for currently published films
    """
    catalog = getToolByName(context, 'portal_catalog')
    items = []
#    import pdb
#    pdb.set_trace()
    for r in  catalog(object_provides=Ihouse.__identifier__,
                        review_state="published",
                        sort_on='sortable_title'):
        tp = (r.Estate, r.Estate)
        if tp not in items and r.Estate !="":
            items.append(tp)
    # This turns a list of title->id pairs into a Zope 3 style vocabulary
    return SimpleVocabulary.fromItems(items)

directlyProvides(SubdistrictVocabularyFactory, IVocabularyFactory)


category_unit=[
('0','new house',_(u'new house')),
('1','secondhand house',_(u'secondhand house')),
('2','rent house',_(u'rent house')),
  ]
bigarea_unit=[
('xiangtanshi','xiangtanshi',_(u'xiangtanshi')),
('shaoshanshi','shaoshanshi',_(u'shaoshanshi')),
('xiangtanxian','xiangtanxian',_(u'xiangtanxian')),
('xiangxiangshi','xiangxiangshi',_(u'xiangxiangshi')),
  ]
area_unit=[
('yuhu','yuhu',_(u'yuhu')),
('yuetang','yuetang',_(u'yuetang')),
('yisuhe','yisuhe',_(u'yisuhe')),
('jiuhua','jiuhua',_(u'jiuhua')),
  ]
biztype_unit=[
('1','sale',_(u'sale')),
('2','renting',_(u'renting')),
  ]
category_terms = [
    SimpleTerm(value, token, title) for value, token, title in category_unit
]
bigarea_terms = [
    SimpleTerm(value, token, title) for value, token, title in bigarea_unit
]
area_terms = [
    SimpleTerm(value, token, title) for value, token, title in area_unit
]
biztype_terms = [
    SimpleTerm(value, token, title) for value, token, title in biztype_unit
]

class CategoryVocabulary(object):    
    """ Ad Unit sizes """
    implements(IVocabularyFactory)

    def __call__(self, context):
        return SimpleVocabulary(category_terms)
CategoryVocabularyFactory = CategoryVocabulary()

class BigareaVocabulary(object):    
    """ Ad Unit sizes """
    implements(IVocabularyFactory)

    def __call__(self, context):
        return SimpleVocabulary(bigarea_terms)
BigareaVocabularyFactory = BigareaVocabulary()

class areaVocabulary(object):    
    """ Ad Unit sizes """
    implements(IVocabularyFactory)

    def __call__(self, context):
        return SimpleVocabulary(area_terms)
areaVocabularyFactory = areaVocabulary()
class biztypeVocabulary(object):    
    """ Ad Unit sizes """
    implements(IVocabularyFactory)

    def __call__(self, context):
        return SimpleVocabulary(biztype_terms)
biztypeVocabularyFactory = biztypeVocabulary()

           

